package com.pro.h5case.admin.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pro.h5case.admin.service.AdminService;
import com.pro.h5case.admin.service.OrderManageService;
import com.pro.h5case.common.model.BAdmin;
import com.pro.h5case.common.model.BDictionary;
import com.pro.h5case.common.model.BOrder;
import com.pro.h5case.common.model.BPlan;
import com.pro.h5case.common.service.BDictionaryService;
import com.pro.h5case.admin.service.PlanManageService;

@Controller
@RequestMapping("/orderManage")
public class OrderManageController {
	@Resource
	private PlanManageService planManageService;
	@Resource
	private BDictionaryService dictionaryService;
	@Resource
	private AdminService adminService;
	@Resource
	private OrderManageService orderManageService;
	
	@RequestMapping(value = "/test", method = {RequestMethod.GET, RequestMethod.POST})
	public String test(Model model, HttpSession session, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
			
			return "admin/planManage/text";
		
	}
	/**
	 * 列表页面
	 */
	@RequestMapping(value = "/list", method = {RequestMethod.GET, RequestMethod.POST})
	public String list(Model model, HttpSession session, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
			Map<String,Object> parameter = new HashMap<String, Object>();
			
			parameter.put("begin", 0);
			parameter.put("size", 15);
			List<BOrder> orderList = orderManageService.selectOrderByMap(parameter);
			
			model.addAttribute("orderList", orderList);
			int planSum = orderManageService.countOrderByMap(parameter);
			int pageSum = planSum / 15;
			if(planSum%15 == 0){
				
			}else{
				pageSum+=1;
			}
			model.addAttribute("pageNo", 1);
			model.addAttribute("pageSum", pageSum);
			return "admin/orderManage/list";
		
	}
	/**
	 * 翻页
	 */
	@RequestMapping(value = "/newPage", method = RequestMethod.POST)
	@ResponseBody
	public Object newPage(Model model, HttpSession session, HttpServletRequest request, HttpServletResponse response,@RequestParam("pageNo") int pageNo,@RequestParam("key") String key,@RequestParam("tag") String tag)
			throws Exception {

			Map<String,Object> parameter = new HashMap<String, Object>();
			parameter.clear();
			parameter.put("begin", pageNo*15);
			parameter.put("size", 15);
			parameter.put("sort", key);
			parameter.put("planTag", tag);
			List<BOrder> orderList = orderManageService.selectOrderByMap(parameter);
			model.addAttribute("orderList", orderList);
			int planSum = orderManageService.countOrderByMap(parameter);
			
			int pageSum = planSum / 15;
			if(planSum%15 == 0){
				
			}else{
				pageSum+=1;
			}
			parameter.clear();
			parameter.put("orderList", orderList);
			parameter.put("pageSum", pageSum);
			parameter.put("pageNo", pageNo);
			return parameter;
		
	}
	
	
}
